﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using outREACH.App_Code;
using System.Net.Mail;

namespace outREACH
{
    public partial class AdminPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null)
            {
                Label lbl1 = (Label)Master.FindControl("Label1");
                lbl1.Text = "Welcome " + Session["Username"].ToString() + "!";
                Label lbl2 = (Label)Master.FindControl("Name");
                Users u = Users.GetName(Session["Username"].ToString());
                lbl2.Text = u.firstName + " " + u.lastName;
                Label lbl3 = (Label)Master.FindControl("Country");
                lbl3.Text = Session["country"].ToString();
                Button btn3 = (Button)Master.FindControl("Button4");
                if (User.IsInRole("admin"))
                {
                    btn3.Visible = true;
                }
            }
            else
            {
                Response.Redirect("~/Default.aspx");
            }
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            
            //ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=300px,width=300px,scrollbars=1');</script>");
            //Session["ctrl"] = Panel11;
            Button6.Attributes.Add("onclick", "return printing()");
            
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            Panel12.Visible = true;
            Panel13.Visible = false;
            Panel14.Visible = false;
        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            Panel12.Visible = false;
            Panel13.Visible = true;
            Panel14.Visible = false;
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            Panel12.Visible = false;
            Panel13.Visible = false;
            Panel14.Visible = true;
        }

        protected void Button9_Click(object sender, EventArgs e)
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress("outreach360@gmail.com", "outREACH360");
            message.To.Add(new MailAddress(TextBox2.Text.ToString()));

            message.Subject = "message from outREACH360";
            message.Body = "Dear Sir/Mdm, " + "\n" + "\n" + TextBox1.Text + "\n" + "With Regards," + "\n" + "outREACH360 Team";

            SmtpClient smtp = new SmtpClient();

            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential("outreach360@gmail.com", "360outreach");

            smtp.Send(message);

            TextBox1.Text = "";
            TextBox2.Text = "";
        }

    }
}